package com.sl.core.engine.meta.hop;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.XmlUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.hop.base.BaseHopMeta;
import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.pipeline.PipelineHopMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.w3c.dom.Node;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ProcessTransHopDescriptor extends PipelineHopMeta {

    @Getter
    @Setter
    private Map<String, Object> attrMap = new ConcurrentHashMap<>();

    public ProcessTransHopDescriptor(Node hopnode, List<TransformMeta> steps) throws HopXmlException {
        super(hopnode, steps);
        Map<String, Object> map = XmlUtil.xmlToMap(hopnode);
        if (MapUtil.isNotEmpty(map)) {
            attrMap.putAll(map);
        }
    }

    public ProcessTransHopDescriptor(PipelineHopMeta transHopMeta) {
//        this.setObjectId(transHopMeta.getObjectId());
        this.setEnabled(transHopMeta.isEnabled());
        this.setChanged(transHopMeta.hasChanged());
        this.setErrorHop(transHopMeta.isErrorHop());
        this.setFromTransform(transHopMeta.getFromTransform());
        this.setToTransform(transHopMeta.getToTransform());
    }

}
